<#assign upName = "${table.entityName}">
<#assign lowName = "${table.entityPath}">

package ${package.ServiceImpl};

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.util.Assert;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.cache.annotation.*;
import org.springframework.stereotype.Service;
import java.io.Serializable;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    /**
    * 保存缓存
    *@Cacheable(cacheNames = "youEntityName", unless = "#result==null")
    * 删除缓存
    *@CacheEvict(cacheNames = "youEntityName",beforeInvocation = true,key = "#id")
    * 更新缓存
    *@CachePut(cacheNames = "youEntityName",key ="#result.id")
    *
    */


    @Cacheable(cacheNames = "${lowName}", unless = "#result==null")
    @Override
    public ${upName} getById(Serializable id) {
        System.out.println("======调用数据库======");
        return super.getById(id);
    }

    /**
    *  这里不直接调用父类的方法，原因是需要保持@Cacheable  @CachePut 的返回值一致，更新缓存才会生效。需要注意！
    */
    @CachePut(cacheNames = "${lowName}",key = "#entity.id")
    @Override
    public ${upName} update${upName}(${upName} entity) {
        Assert.hasText(entity.getId(),"缺少id");
        update(new UpdateWrapper<>(entity)
<#list table.fields as field>
    <#if !field.keyFlag>
            .set(StringUtils.checkValNotNull(entity.get${field.capitalName}()), "${field.name}", entity.get${field.capitalName}())
    </#if>
</#list>
        );
        return super.getById(entity.getId());
    }

    @CacheEvict(cacheNames = "${lowName}",beforeInvocation = true,key = "#id")
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }
}

